#include "edu_fiu_cis_selfhealingdisk_DiskSimJNIInterface.h"
#include "disksim_jni_interface.h"

JNIEXPORT void JNICALL Java_edu_fiu_cis_selfhealingdisk_DiskSimJNIInterface_startSimulation
  (JNIEnv *env, jobject obj, jstring parameterfile, jstring outputfile) {
  	
  	jbyte *jparameterfile = (*env)->GetStringUTFChars(env, parameterfile,NULL);
  	jbyte *joutputfile = (*env)->GetStringUTFChars(env, outputfile, NULL); 
  	
  	shd_start_simulation(jparameterfile, joutputfile);
}

JNIEXPORT void JNICALL Java_edu_fiu_cis_selfhealingdisk_DiskSimJNIInterface_sendRequest
  (JNIEnv *env, jobject obj, jlong timestamp, jint type, jlong block, jlong byte_count, jlong request_id) {
 	
  	shd_send_request(((double)timestamp)/1e6,type,(unsigned long)block,(int) byte_count, request_id);
  	  	
}

JNIEXPORT void JNICALL Java_edu_fiu_cis_selfhealingdisk_DiskSimJNIInterface_setTime
  (JNIEnv *env, jobject obj, jlong timestamp) {

  	shd_set_time(((double)timestamp)/1e6);
  	
}

JNIEXPORT jlongArray JNICALL Java_edu_fiu_cis_selfhealingdisk_DiskSimJNIInterface_getEvents
  (JNIEnv *env, jobject obj) {
  	
  	long long * events;
  	int array_size;
  	
  	shd_get_events(&events,&array_size);
  	  		
  	jlongArray jni_requests = (*env)->NewLongArray(env,array_size);
	(*env)->SetLongArrayRegion(env, jni_requests, 0, array_size, events);
  	
 	return jni_requests;
}

JNIEXPORT void JNICALL Java_edu_fiu_cis_selfhealingdisk_DiskSimJNIInterface_finishSimulation
  (JNIEnv *env, jobject obj) {
  	
  	shd_finish_simulation();
  	
}
